package com.ibl.rover.lite.handler;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.ibl.rover.lite.service.utill.Core;
import com.ibl.rover.lite.service.utill.Core.ROUTE;
import com.ibl.rover.lite.service.utill.HibernateUtill;
import com.ibl.rover.lite.service.utill.Core.SST_TAGS;
import com.rover.lite.hibernate.dal.RvrAppsetup;
import com.rover.lite.hibernate.dal.RvrCustomers;
import com.rover.lite.hibernate.dal.RvrPrdcategory;
import com.rover.lite.hibernate.dal.RvrProducts;
import com.rover.lite.hibernate.dal.RvrRouteqry;
import com.rover.lite.hibernate.dal.RvrRoutes;


public class RouteHandler {
	Session session;
	Document doc;

	
	public RouteHandler(Document _doc) {
		// TODO Auto-generated constructor stub
		session = HibernateUtill.getSessionFactory().openSession();
		doc = _doc;
	} 
	
	
	
public void getProductCategory(Element bodyElement, String userName) {
	
		
		Criteria rvrRoutesCriteria = session
				.createCriteria(RvrRoutes.class);
	
		rvrRoutesCriteria.add(Restrictions.eq("id.xtso", userName));
		
		
 	
 
		List<RvrRoutes>  listRvrRoutes = new ArrayList<RvrRoutes>();
		listRvrRoutes=rvrRoutesCriteria.list();

		Element entityElement = doc.createElement("entity");
		entityElement.setAttribute("name", SST_TAGS.ROUTE);
		bodyElement.appendChild(entityElement);

		Element addElement = doc.createElement("add");
		entityElement.appendChild(addElement);
		
		
		for (RvrRoutes rvrRoutes : listRvrRoutes) {
			Element itemElement = doc.createElement("item");
			addElement.appendChild(itemElement);
			setRvrRoutesAttribute(rvrRoutes, itemElement);

		}

	}

	
	private void setRvrRoutesAttribute(RvrRoutes rvrRoutes,
			Element itemElement) {

		try {
			ArrayList<String> columnName = new ArrayList<String>();
			ArrayList<String> columnValue = new ArrayList<String>();
			//
			columnName.add(ROUTE.xDay);
			columnValue.add(String.valueOf(rvrRoutes.getId().getXday()));
			
			columnName.add(ROUTE.xRoute);
			columnValue.add(String.valueOf(rvrRoutes.getId().getXroute()));
			
		 
			
			
			Core.setAttribute(columnName, columnValue, itemElement, doc);
		} catch (Exception e) {

		}

	}


	
}
